<template>
  <div class="home">
    <MyEcharts />
    <el-row class="home-line">
      <el-col :span="12" :offset="4">
        <el-input v-model="inputStr" placeholder="请输入内容"></el-input>
      </el-col>
      <el-col :span="4">
        <el-button type="primary" @click="setStore">设置存储</el-button>
      </el-col>
    </el-row>
    <el-row class="home-line">
      <el-col :span="12" :offset="4">{{ storeStr }}</el-col>
      <el-col :span="4">
        <el-button type="primary" @click="getStore">获取存储</el-button>
      </el-col>
    </el-row>
    <el-row class="home-line">
      <el-col :span="12" :offset="6">
        <el-button type="primary" @click="clearStore">清除存储</el-button>
        <el-button type="primary" @click="openFile">打开文件</el-button>
        <el-button type="primary" @click="openDirectory">打开目录</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import MyEcharts from '@/components/MyEcharts'
  export default {
    name: 'Home',
    components: {
      MyEcharts
    },
    data() {
      return {
        inputStr: '',
        storeStr: '存储为空'
      }
    },
    methods: {
      openDefaultBrowsers(url) {
        bridgeApi.openWithDefaultBrowser(url)
      },
      setStore() {
        bridgeApi.setStore('configStr', this.inputStr)
      },
      getStore() {
        this.storeStr = bridgeApi.getStore('configStr') || '存储为空'
      },
      clearStore() {
        bridgeApi.clearStore()
      },
      openFile() {
        bridgeApi.getFile(res => {
          console.log(res)
        })
      },
      openDirectory() {
        bridgeApi.getDirectory(res => {
          console.log(res)
        })
      }
    }
  }
</script>
<style lang="scss" scoped>
  .home {
    text-align: center;
    vertical-align: middle;
    .home-line {
      margin-bottom: 20px;
    }
  }
</style>
